package com.newenergy.wisehome.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.newenergy.wisehome.R;
import com.newenergy.wisehome.config.AppManager;
import com.newenergy.wisehome.data.bean.DeviceCategory;

import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.ISupportFragment;

/**
 * Created by kyx on 2018/5/4.
 * 晾衣架操作界面--7207
 */

public class ClotheshorseFragment extends BaseFragment {


    private static String ARG_CLOTHESHORSE="arg_clotheshorse";
    @BindView(R.id.btn_back)
    Button mBtnBack;
    @BindView(R.id.tv_back)
    TextView mTvBack;
    @BindView(R.id.tv_page)
    TextView mTvPage;
    @BindView(R.id.btn_up)
    Button mBtnUp;
    @BindView(R.id.btn_lighting)
    Button mBtnLighting;
    @BindView(R.id.btn_stop)
    Button mBtnStop;
    @BindView(R.id.btn_dry)
    Button mBtnDry;
    @BindView(R.id.btn_down)
    Button mBtnDown;
    @BindView(R.id.btn_sterilize)
    Button mBtnSterilize;

    protected DeviceCategory mDeviceCategory;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_clotheshorse;
    }

    public static ISupportFragment newInstance(DeviceCategory mainItem) {
        Bundle args = new Bundle();
        args.putParcelable(ARG_CLOTHESHORSE, mainItem);
        ClotheshorseFragment fragment = new ClotheshorseFragment();
        fragment.setArguments(args);
        return fragment;
    }



    @Override
    public void init(View rootView) {
        mDeviceCategory = getArguments().getParcelable(ARG_CLOTHESHORSE);

        mTvPage.setText(mDeviceCategory.getName());


    }

    @Override
    public void onResume() {
        super.onResume();
        if (mDeviceCategory != null) {
            AppManager.getInstance(getContext()).mSelectDeviceCategory = mDeviceCategory;
        }
    }

    @OnClick({R.id.btn_back, R.id.tv_back, R.id.btn_up, R.id.btn_lighting, R.id.btn_stop, R.id.btn_dry, R.id.btn_down, R.id.btn_sterilize})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                doBack();
                break;
            case R.id.tv_back:
                doBack();
                break;
            case R.id.btn_up:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"01000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7207");

                break;
            case R.id.btn_lighting:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"02000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7207");

                break;
            case R.id.btn_stop:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"03000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7207");

                break;
            case R.id.btn_dry:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"04000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7207");

                break;
            case R.id.btn_down:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"05000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7207");

                break;
            case R.id.btn_sterilize:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"06000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7207");

                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mDeviceCategory = null;
    }


}
